<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Kafka ISR 机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">深入理解 Kafka ISR 机制</h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">探索分布式系统中的数据一致性与高可用性核心</p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>高可用性保障</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i>
                        <span>数据同步机制</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-server mr-2"></i>
                        <span>分布式架构</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    Kafka 的 ISR（In-Sync Replicas）机制是其高可用性和数据一致性的核心组成部分。ISR 机制确保了在 Kafka 集群中数据的可靠性和一致性，即使在节点失败或网络分区的情况下。
                </p>
            </div>
        </div>
    </section>

    <!-- ISR Architecture Diagram -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center mb-12 text-gradient">ISR 架构概览</h2>
            <div class="mermaid">
                graph TB
                    subgraph "Kafka Partition"
                        L[Leader Replica<br/>处理读写请求]
                        F1[Follower 1<br/>同步中]
                        F2[Follower 2<br/>同步中]
                        F3[Follower 3<br/>落后]
                    end
                    
                    subgraph "ISR List"
                        ISR[ISR 列表<br/>Leader, Follower 1, Follower 2]
                    end
                    
                    L -->|数据复制| F1
                    L -->|数据复制| F2
                    L -.->|数据复制延迟| F3
                    
                    F1 --> ISR
                    F2 --> ISR
                    F3 -.->|移出 ISR| ISR
                    
                    Client[客户端] -->|写入请求| L
                    L -->|确认| Client
                    
                    style L fill:#667eea,stroke:#fff,color:#fff
                    style F1 fill:#764ba2,stroke:#fff,color:#fff
                    style F2 fill:#764ba2,stroke:#fff,color:#fff
                    style F3 fill:#e53e3e,stroke:#fff,color:#fff
                    style ISR fill:#48bb78,stroke:#fff,color:#fff
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <!-- ISR Definition -->
                <div class="mb-16 animate-fadeInUp">
                    <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                        <span class="mr-2">1.</span> ISR 的定义
                    </h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gradient-to-br from-purple-50 to-indigo-50 p-6 rounded-lg card-hover">
                            <div class="flex items-start">
                                <i class="fas fa-book-open text-2xl feature-icon mr-4 mt-1"></i>
                                <div>
                                    <h4 class="font-bold text-lg mb-2">定义</h4>
                                    <p class="text-gray-700">ISR 是一个包含当前分区数据副本的集合，所有副本都与主副本（Leader）保持同步。换句话说，ISR 是所有与 Leader 副本保持数据一致的从副本（Follower）列表。</p>
                                </div>
                            </div>
                        </div>
                        <div class="bg-gradient-to-br from-purple-50 to-indigo-50 p-6 rounded-lg card-hover">
                            <div class="flex items-start">
                                <i class="fas fa-bullseye text-2xl feature-icon mr-4 mt-1"></i>
                                <div>
                                    <h4 class="font-bold text-lg mb-2">作用</h4>
                                    <p class="text-gray-700">ISR 确保所有副本的数据都与 Leader 副本一致，确保数据的高可用性和一致性。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Leader and Follower Roles -->
                <div class="mb-16 animate-fadeInUp">
                    <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                        <span class="mr-2">2.</span> Leader 和 Follower 的角色
                    </h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-white border-2 border-purple-200 p-6 rounded-lg card-hover">
                            <div class="text-center mb-4">
                                <i class="fas fa-crown text-4xl text-gradient"></i>
                            </div>
                            <h4 class="font-bold text-xl mb-3 text-center">Leader</h4>
                            <p class="text-gray-700">每个 Kafka 分区都有一个 Leader 副本，负责处理所有的读写请求。Leader 副本的角色是协调数据的写入和读取。</p>
                        </div>
                        <div class="bg-white border-2 border-purple-200 p-6 rounded-lg card-hover">
                            <div class="text-center mb-4">
                                <i class="fas fa-users text-4xl text-gradient"></i>
                            </div>
                            <h4 class="font-bold text-xl mb-3 text-center">Follower</h4>
                            <p class="text-gray-700">除了 Leader 副本外，其他副本都是 Follower 副本。Follower 副本从 Leader 副本那里复制数据，并保持数据的同步。</p>
                        </div>
                    </div>
                </div>

                <!-- ISR Management -->
                <div class="mb-16 animate-fadeInUp">
                    <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                        <span class="mr-2">3.</span> ISR 的管理
                    </h3>
                    <div class="bg-gradient-to-r from-indigo-50 to-purple-50 p-8 rounded-lg">
                        <div class="grid md:grid-cols-2 gap-8">
                            <div class="flex items-start">
                                <div class="bg-green-500 text-white rounded-full w-12 h-12 flex items-center justify-center mr-4 flex-shrink-0">
                                    <i class="fas fa-plus"></i>
                                </div>
                                <div>
                                    <h4 class="font-bold text-lg mb-2">加入 ISR</h4>
                                    <p class="text-gray-700">当一个副本（Follower）成功地从 Leader 副本中拉取数据并保持同步时，它会被加入到 ISR 列表中。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-red-500 text-white rounded-full w-12 h-12 flex items-center justify-center mr-4 flex-shrink-0">
                                    <i class="fas fa-minus"></i>
                                </div>
                                <div>
                                    <h4 class="font-bold text-lg mb-2">移出 ISR</h4>
                                    <p class="text-gray-700">如果一个副本落后于 Leader 副本的数据，或者与 Leader 副本的连接中断，该副本会被移出 ISR 列表。移出 ISR 的副本不再被视为与 Leader 副本同步的数据副本。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- ISR and Data Writing -->
                <div class="mb-16 animate-fadeInUp">
                    <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                        <span class="mr-2">4.</span> ISR 与数据写入
                    </h3>
                    <div class="space-y-6">
                        <div class="bg-white shadow-lg rounded-lg p-6 card-hover">
                            <div class="flex items-center mb-3">
                                <i class="fas fa-check-circle text-green-500 text-2xl mr-3"></i>
                                <h4 class="font-bold text-lg">写入确认</h4>
                            </div>
                            <p class="text-gray-700">Kafka 的写入请求需要获得 ISR 中副本的确认才会被认为成功。这保证了写入操作在多个副本中都被正确复制，从而实现高可用性。</p>
                        </div>
                        <div class="bg-white shadow-lg rounded-lg p-6 card-hover">
                            <div class="flex items-center mb-3">
                                <i class="fas fa-cog text-blue-500 text-2xl mr-3"></i>
                                <h4 class="font-bold text-lg">配置项</h4>
                            </div>
                            <p class="text-gray-700">Kafka 允许通过 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">min.insync.replicas</code> 配置项来设置写入请求成功所需的最小副本数。即使一个副本故障，只要剩余的副本仍在 ISR 中满足该数量，写入请求仍然会被认为成功。</p>
                        </div>
                    </div>
                </div>

                <!-- ISR Fault Tolerance -->
                <div class="mb-16 animate-fadeInUp">
                    <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                        <span class="mr-2">5.</span> ISR 的容错性
                    </h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gradient-to-br from-orange-50 to-red-50 p-6 rounded-lg">
                            <i class="fas fa-exclamation-triangle text-3xl text-orange-500 mb-4"></i>
                            <h4 class="font-bold text-lg mb